const path = require("path")
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { VueLoaderPlugin } = require('vue-loader')
const { type } = require("os");

module.exports = {
    entry: "./src/main.js", // 入口
    output: { 
        path: path.join(__dirname, "dist"), // 出口路径
        filename: "bundle.js" // 出口文件名
    },
    plugins: [
        new HtmlWebpackPlugin({ template: './public/index.html' }),
        new MiniCssExtractPlugin(),
        new VueLoaderPlugin()
    ],
    module: { 
        rules: [ // loader的规则
            {
                test: /\.vue$/,
                loader: 'vue-loader'
              },
          {
            test: /\.css$/, // 匹配所有的css文件
            // use数组里从右向左运行
            // 先用 css-loader 让webpack能够识别 css 文件的内容并打包
            // 再用 style-loader 将样式, 把css插入到dom中
            use: [ MiniCssExtractPlugin.loader, "css-loader"]
        },
        {
          test: /\.less$/,
          use:[MiniCssExtractPlugin.loader,"css-loader","less-loader"]
            },
            {
            test:/\.(png|jpg|gif|ipeg)$/,
            type:"asset"
            },
            {
                test: /\.(eot|svg|ttf|woff|woff2)$/,
                type: "asset/resource",
                generator: {//生成文件名字-定义规则
                    filename: 'font/[name].[hash:6][ext]'
                }
            }
          
        ]
    }
}